package ch04;

/**
 * @author chenmin
 * @desc TODO
 * @date 2025/9/2
 */
public class Person {
    String name;
    int age;
    boolean gender; // true 男，false 女
    Person partner; // 伴侣

    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public void marry(Person p) {
        // 检查是否同性
        if (this.gender == p.gender) {
            System.out.println(this.name + "和" + p.name +"不能结婚，因为是同性。");
            return;
        }
        // 检查是否未达到结婚年龄
        if ((this.gender && this.age < 24) || (!this.gender && this.age < 22)) {
            System.out.println(this.name + "未达到结婚年龄，不能结婚。");
            return;
        }
        if ((p.gender && p.age < 24) || (!p.gender && p.age < 22)) {
            System.out.println(p.name + "未达到结婚年龄，不能结婚。");
            return;
        }
        // 检查是否某一方已婚
        if (this.partner != null) {
            System.out.println(this.name + "已经已婚，不能结婚。");
            return;
        }
        if (p.partner != null) {
            System.out.println(p.name + "已经已婚，不能结婚。");
            return;
        }
        // 可以结婚，设置伴侣
        this.partner = p;
        p.partner = this;
        System.out.println("恭喜" + this.name + "和" + p.name + "结婚！");
    }

    public static void main(String[] args) {
        Person person1 = new Person("辣椒", 25, true);
        Person person2 = new Person("炒肉", 23, false);
        Person person3 = new Person("小梅", 22, true);
        Person person4 = new Person("啾啾", 21, false);
        Person person5 = new Person("木薯", 26, true);
        person5.partner = new Person("Nekko", 24, false);

        person1.marry(person2);
        person3.marry(person4);
        person1.marry(person5);
    }
}